package com.sky.controller.user;

import com.sky.dto.CategoryDrugCreateDTO;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.vo.CategoryDrugDetailVO;
import com.sky.vo.CategoryDrugVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/user/category")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 添加药品到组合
     *
     * @param ids 药品们的ids
     * @return
     */
    @PostMapping("/add")
    public Result addCategoryGroup(@RequestParam List<Long> ids, @RequestParam String categoryName) {
        CategoryDrugCreateDTO categoryDrugCreateDTO = new CategoryDrugCreateDTO(categoryName, ids);
        log.info("获取的字段：{}", categoryDrugCreateDTO);
        categoryService.addCategoryGroup(categoryDrugCreateDTO);
        return Result.success();

    }

    /**
     * 展示药品组合信息
     *
     * @return 药品组合
     */
    @GetMapping("/list")
    public Result<List<CategoryDrugVO>> list() {
        List<CategoryDrugVO> categoryDrugVOS = categoryService.getCategoryList();
        return Result.success(categoryDrugVOS);
    }

    /**
     * 获取组合药品的详情
     *
     * @param id 组合id
     * @return
     */
    @GetMapping("/detail/{id}")
    public Result<List<CategoryDrugDetailVO>> getCategoryDrugDetail(@PathVariable Long id) {
        List<CategoryDrugDetailVO> categoryDrugDetailVOS = categoryService.getCategoryDrugDetail(id);
        return Result.success(categoryDrugDetailVOS);
    }
}

